<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>助理管理</title>
<!-- 360浏览器以极速模式显示 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/matrix-style.css" />
<link rel="stylesheet" href="css/matrix-media.css" />
<link rel="stylesheet" href="jquery-easyui/themes/default/easyui.css" />
<link rel="stylesheet" href="jquery-easyui/themes/icon.css" />
<script type="text/javascript" src="jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
<script charset="utf-8" src="editor/kindeditor-all.js"></script>
<script charset="utf-8" src="editor/lang/zh-CN.js"></script>
<link rel='stylesheet' href="editor/themes/default/default.css"></link>
<script type="text/javascript" src="editor/plugins/code/prettify.js"></script>
<style>
 .content-header{
/*   margin-top:-38px;
 */  font-size:16px;
  background-color:#fff;
 }
 .content-header table{
  font-weight:bolder;
  margin-left:30px;
 }
 .content-header .header-number{
  margin-left:10px;
 }
  .width30{
   width:50%;
  }
  .width70{
   width:50%;
  }
  .table th, .table td{
    text-align:center;
  }
  /*easyui*/
  	#fm{
			margin:0;
			padding:10px 30px;
		}
		.ftitle{
			font-size:14px;
			font-weight:bold;
			padding:5px 0;
			margin-bottom:10px;
			border-bottom:1px solid #ccc;
		}
		.fitem{
			margin-bottom:5px;
		}
		.fitem label{
			display:inline-block;
			width:80px;
		}
		.fitem input{
			width:160px;
		}
</style>

<script type="text/javascript">
$(document).ready(function(){
	$.ajax({
		url:"<%=request.getContextPath()%>/task?method=taskcount",
		dataType:'json',
		type:'post',
		data:{},
		beforeSend:function(){
			
		},
		success:function(result){
			if(result.success){
				$("#count").text(result.count);
			}
		}
	})
})
function newUser(){
    $('#dlg').dialog('open').dialog('setTitle','New Assist');
    $('#fm').form('clear');
    url = '<%=request.getContextPath()%>/assist?method=add';
}
function changePass(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
	    $('#dlg1').dialog('open').dialog('setTitle','Update Password');
	    $('#fm1').form('load',row);
	    url = '<%=request.getContextPath()%>/assist?method=updatepwd&id='+row.id;
	}
}
function editUser(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
	    $('#dlg3').dialog('open').dialog('setTitle','Edit Assist');
	    $("#fm3").form("load",row);
	    url = '<%=request.getContextPath()%>/assist?method=update&id='+row.id;
	    
	  
	}
}
function dispatch(){
	var row = $('#dg').datagrid('getSelected');
	if(row){
	    $('#dlg4').dialog('open').dialog('setTitle','dispatch user');
	    $("#dg2").datagrid({
	    	url:"<%=request.getContextPath()%>/assist?method=noassignlist"
	    			
	    })
	}

}
function dodispatch(){
	var ids = [];
	var rows = $('#dg2').datagrid('getSelections');
	for(var i=0; i<rows.length; i++){
		ids.push(rows[i].uid);
	}
	$.ajax({
		url:"<%=request.getContextPath()%>/assist?method=dispatch&id="+$('#dg').datagrid('getSelected').id,
	    type:"post",
	    dataType:"json",
	    data:{ids:""+ids},
	    beforeSend:function(){
	    	if(ids.length<=0){
	    		$.messager.show({
                    title: 'Error',
                    msg: "没有选中用户"
                });
	    		return false;
	    	}
	    	return true;
	    },
	    success:function(data){
	    	if(data.success){
	    		$.messager.show({
                    title: 'success',
                    msg: "分配成功"
                });
              $('#dg2').datagrid('reload');    // reload the user data
	    	}
	    }
	});
}
function readinfo(){
	var row = $('#dg').datagrid('getSelected');
	if(row){
	    $('#dlg2').dialog('open').dialog('setTitle','Assist info');
	    $("#dlg2 .id").text(row.id);
	    $("#dlg2 .name").text(row.name);
	    $("#dlg2 .department").text(row.department);
	    $("#dlg2 .phone").text(row.phone);
	    $("#dlg2 .email").text(row.email);
	    $("#dlg2 .wxid").text(row.wxid);
	    $("#dlg2 .wxcode").attr("src",row.wxcode);
	}
}
function doadd(){
    $('#fm').form('submit',{
        url: url,
        onSubmit: function(){
             if(!$(this).form('validate')){
            	 return false;
             }
        },
        success: function(result){
            var result = eval('('+result+')');
            if (!result.success){
                $.messager.show({
                    title: 'Error',
                    msg: result.msg
                });
            } else {
                $('#dlg').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}
function updatepwd(){
	    $('#fm1').form('submit',{
	        url: url,
	        onSubmit: function(){
	             if(!$(this).form('validate')){
	            	 return false;
	             }
	        },
	        success: function(result){
	            var result = eval('('+result+')');
	            if (!result.success){
	                $.messager.show({
	                    title: 'Error',
	                    msg: result.msg
	                });
	            } else {
	                $('#dlg1').dialog('close');        // close the dialog
	                $('#dg').datagrid('reload');    // reload the user data
	            }
	        }
	    });
}
function doUpdate(){
	$('#fm3').form('submit',{
        url: url,
        onSubmit: function(){
             if(!$(this).form('validate')){
            	 return false;
             }
        },
        success: function(result){
            var result = eval('('+result+')');
            if (!result.success){
                $.messager.show({
                    title: 'Error',
                    msg: result.msg
                });
            } else {
                $('#dlg3').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}
function ownUser(){
	var row=$("#dg").datagrid("getSelected");
	if(row){
	    $('#dlg5').dialog('open').dialog('setTitle','the users belong to the assist');
	    $("#dg3").datagrid({
	    	url:"<%=request.getContextPath()%>/assist?method=hasuser&id="+row.id
	    })
	}
}
function dodelete(){
	var ids=[];
	var rows=$("#dg3").datagrid("getSelections");
	for(var i=0;i<rows.length;i++){
		ids.push(rows[i].uid);
	}
	
	$.ajax({
		url:"<%=request.getContextPath()%>/assist?method=deleteuser&id="+$("#dg").datagrid("getSelected").id,
		dataType:"json",
		type:"post",
		data:{ids:""+ids},
		beforeSend:function(){
			if(ids.length<=0){
				$.messager.show({
					title:"Error",
					msg:"没有选中用户"
				});
				return false;
			}
			return true;
		},
		success:function(data){
			if(data.success){
				$.messager.show({
					title:"Success",
					msg:"删除成功"
				})
				$("#dg3").datagrid("reload");
			}
		}
	})
	
}

function destroyUser(){
    var row = $('#dg').datagrid('getSelected');
    if (row){
        $.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
            if (r){
                $.post('<%=request.getContextPath()%>/assist?method=deleteassist',{id:row.id},function(result){
                    if (result.success){
                        $('#dg').datagrid('reload');    // reload the user data
                    } else {
                        $.messager.show({    // show error message
                            title: 'Error',
                            msg: '删除助理失败'
                        });
                    }
                },'json');
            }
        });
    }
}
</script>
<script>
 function logout(){
		$.messager.confirm('Confirm','Are you sure you want to logout?',function(r){
            if (r){
                $.post('<%=request.getContextPath()%>/logout',function(result) {
					if (result.success) {
						$.messager.show({ // show error message
							title : '提示',
							msg : '退出成功'
						});
			           }
				 else {
						$.messager.show({ // show error message
									title : '提示',
									msg : '登录已过期，重新登录'
								});
					   }
				}, 'json');
    			window.open('<%=request.getContextPath()%>/index.jsp','_self');

		     }
	});
}

</script>
<!-- 修改资料 -->
<script type="text/javascript">

var editor;
KindEditor.ready(function (K) {
	//这里是kindeditor编辑器的基本初始化配置
 	 editor = K.create('#content_id', {
		resizeType: 1,
		fullscreenMode: 0, //是否全屏显示
		designMode: 1,
		uploadJson:'editor/jsp/upload_json.jsp',
	    fileManagerJson : 'editor/jsp/file_manager_json.jsp',
		allowPreviewEmoticons: false,
		allowImageUpload: true,
		allowFileManager: true
	}); 
	//这里是监听按钮点击事件 然后在初始化点击按钮弹窗上传图片的基本配置
	K('#image').click(function () {
	editor.loadPlugin('image', function () {
	editor.plugin.imageDialog({
	imageUrl: K('#url').val(),
	clickFn: function (url, title, width, height, border, align) {
		K('#url').val(url);
		editor.hideDialog();
	}
	});
	});
	});
 });
//隐藏editor编辑器
$(document).ready(function(){
	$("#div").css("display","none");

})
</script>
<script>
 $(document).ready(function(){
	var ddlMenu1 = $('#li1').menubutton({ menu: '#cusmenu1' }); 
	var ddlMenu2 = $('#li2').menubutton({ menu: '#cusmenu2' }); 
	//menubutton 依赖于 menu、linkbutton 这两个插件，所以我们可以这样搞定她
	$(ddlMenu1.menubutton('options').menu).menu({
            onClick: function (item) {
            	if(item.id=='id1'){
            		
            	}else if(item.id=='id2'){
                    window.open("<%=request.getContextPath()%>/task?method=assisttasks","_blank")

            	}else if(item.id=='id3'){
                    window.open("<%=request.getContextPath()%>/","_self")
            		
            	}
            }
	})
	$(ddlMenu2.menubutton('options').menu).menu({
	            onClick: function (item) {
	            	 if(item.id=='id4'){
	            	}
	            }
	})
})
function profile(){
	window.open('<%=request.getContextPath()%>/profile?method=page','_self');
}
function gohome(){
	window.open('<%=request.getContextPath()%>/dashboard','_self');
}

function gotoMytask(){
	window.open('<%=request.getContextPath()%>/task','_self');
	
}
</script>
</head>
<body>
<!--Header-part-->
<div id="header">
  <h1><a href="dashboard.html">Matrix Admin</a></h1>
</div>
<!--close-Header-part--> 

<!-- header menu -->
<ul style="position:absolute;left:200px;top:20px;list-style:none;">
<c:choose>
 <c:when test="${sessionScope.assist.type eq 1}">
   <li id="li1" style="float:left;padding:5px;color:#0094ff;font-size:12px;" icon="icon-lightning">welcome you</li>
  <div id="cusmenu1" style="width:150px;">
   <div id="id1">我的资料</div>
   <div id="id2">我的任务</div>
   <div class="menu-sep"></div>
</div>
 </c:when>
 <c:otherwise></c:otherwise>
</c:choose>
 <li id="li2" style="float:left;padding:5px;color:#0094ff;font-size:12px;" icon="icon-lightning" onclick="gohome()">首页</li>
</ul>

<!-- header menu -->
<!-- header menu -->
<div id="welcome" >
<h3 style="position:absolute;top:5px;right:30px;font-size:16px;height:35px;line-height:32px;background:white;border-radius:10px 10px">
<a href="#" onclick='gotoMytask()'><span style="padding:5px;border-radius:10px 10px ;color:white;background:red;" id="count"></span></a>
<a href="#" class="easyui-menubutton" data-options="menu:'#mm5',iconCls:'icon-man'" style="color:#0094ff;">${sessionScope.assist.id }</a>
</h3>
</div>
<div id="mm5" style="width:150px;">
		<div data-options="iconCls:'icon-undo'" onclick="profile()">个人设置</div>
		<div class="menu-sep"></div>
		<div>我的任务</div>
		<div class="menu-sep"></div>
		<div>系统消息</div>
		<div class="menu-sep"></div>
		<div onclick="logout()">安全退出</div>
</div>
<!-- side bar start -->
<div id="sidebar" >
  <ul>
    <li ><a  href="<%=request.getContextPath()%>/dashboard"><i class="icon icon-home"></i> <span>Dashboard控制面板</span></a> </li>
    <li> <a href="<%=request.getContextPath()%>/study?method=page"><i class="icon icon-signal"></i> <span>Study news留学信息</span></a> </li>
    <li> <a href="<%=request.getContextPath()%>/travel?method=page"><i class="icon icon-inbox"></i> <span>Travel New活动信息</span></a> </li>
    <li><a href="<%=request.getContextPath()%>/news?method=page"><i class="icon icon-th"></i> <span>Recent News近期新闻</span></a></li>
    <li><a href="<%=request.getContextPath()%>/member?method=page"><i class="icon icon-fullscreen"></i> <span>Members centre会员中心</span></a></li>
    <c:choose>
     <c:when test="${sessionScope.assist.type eq 0}">
      <li class="active" ><a href="<%=request.getContextPath() %>/assist"><i class="icon icon-th-list"></i> <span>助理管理</span></a></li>
     </c:when>
    </c:choose>
    <li><a href="<%=request.getContextPath() %>/task"><i class="icon icon-th-list"></i> <span>任务管理</span></a></li>
    
  </ul>
</div>
<div id="content">
 <table id="dg" title="助理管理" class="easyui-datagrid" url="<%=request.getContextPath() %>/assist?method=list"
       toolbar="#toolbar"  pagination="true" rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
        <tr>
            <th field="id" width="40">编号</th>
            <th field="name" width="40">姓名</th>
            <th field="department" width="40" >部门</th>
            <th field="phone" width="40">电话</th>
            <th field="task" width="40">任务数量</th>
            <th field="email" hidden  width="40">邮箱</th>
            <th field="wxid"  hidden width="40">微信号</th>
            <th field="wxcode" hidden  width="40">二维码</th>
        </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增助理</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="changePass()">修改助理密码</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-man" plain="true" onclick="readinfo()">查看详细资料</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改助理资料</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="dispatch()">分配用户 </a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-large-smartart" plain="true" onclick="ownUser()">查看助理负责的用户 </a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除助理</a>
</div>
<!-- dialog弹出框 -->
<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
        closed="true" buttons="#dlg-buttons" >
    <div class="ftitle" style="text-align:center;">创建一个助理账号</div>
    <form id="fm" method="post" novalidate>
        <div class="fitem">
            <label>编号:</label>
            <input name="id" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>姓名:</label>
            <input name="name" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>密码:</label>
            <input name="password" class="easyui-textbox" required="true">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="doadd()" style="width:90px">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
</div>

<div id="dlg1" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
        closed="true" buttons="#dlg-buttons1" >
    <div class="ftitle" style="text-align:center;">修改密码</div>
    <form id="fm1" method="post" novalidate>
        <div class="fitem">
            <label>旧密码:</label>
            <input name="password" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>输入新密码:</label>
            <input name="password2" class="easyui-textbox" required="true">
        </div>
    </form>
</div>
<div id="dlg-buttons1">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="updatepwd()" style="width:90px">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg1').dialog('close')" style="width:90px">Cancel</a>
</div>

<div id="dlg2" class="easyui-dialog" style="width:500px;height:630px;padding:10px 20px"
        closed="true" buttons="#dlg-buttons2">
    <div class="ftitle" style="text-align:center;">助理账号信息</div>
        <table class="table table-bordered table-striped">
         <tbody>
           <tr>
           <tr>
             <td> ID:</td>
             <td class="id"></td>
           </tr>
           <tr>
             <td>姓名</td>
             <td class="name"></td>
           </tr>
           <tr>
             <td>所属部门</td>
             <td class="department"></td>
           </tr>
           <tr>
           <td >联系电话</td>
           <td  class="phone"></td>
           </tr>
           <tr>
            <td>邮箱</td>
            <td class="email"></td>
           </tr>
           <tr>
            <td>微信id</td>
            <td>
              <div class="wxid"></div>
              <hr/>
              <img class="wxcode" style="width:200px;height:150px;" alt=""/>
            </td>
           </tr>
           <tr>
            <td>目前任务数量</td>
            <td>0</td>
           </tr>
           </tbody>
       </table>
    </div>
	<div id="dlg-buttons2">
	    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg2').dialog('close')" style="width:90px">Cancel</a>
	</div>
  </div>
  <div id="dlg3" class="easyui-dialog" style="width:500px;height:400px;padding:10px 20px"
        closed="true" buttons="#dlg-buttons3" >
    <div class="ftitle" style="text-align:center;">修改助理资料</div>
     <form id="fm3" method="post"  novalidate>
        <div class="fitem">
            <label>姓名:</label>
            <input name="name"  required="true">
        </div>
        <div class="fitem">
            <label>部门:</label>
            <input name="department"  required="true">
        </div>
        <div class="fitem">
            <label>手机号:</label>
            <input name="phone"  required="true">
        </div><div class="fitem">
            <label>邮箱:</label>
            <input name="email"  required="true">
        </div>
        <div class="fitem">
            <label>微信id:</label>
            <input name="wxid"  required="true">
        </div>
        <div class="fitem">
            <label>二维码:</label>
             <input type="text" id="url" style="width:151px;height:12px;border-radius:5px 5px" name="wxcode" required="true">
             <input type="button" id="image" style="width:151px;height:22px;line-height:17px;position:relative;top:-5px;" value="选择图片" />
		     <div id="div"><textarea name="content" id="content_id"></textarea></div>
        </div>
      </form>
    </div>
<div id="dlg-buttons3">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="doUpdate()" style="width:90px">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg3').dialog('close')" style="width:90px">Cancel</a>
</div>
  
<div id="dlg4"  class="easyui-dialog" style="width:800px;height:600px;padding:10px 20px" 
        closed="true" buttons="#dlg-buttons4">
          <div class="ftitle" style="text-align:center;">给助理分配用户</div>
       <table id="dg2" title="" class="easyui-datagrid" 
          pagination="true" rownumbers="true" fitColumns="true"  idField="uid">
	    <thead>
	        <tr>
		        <th field="ck" width="40" checkbox="true"></th>
	            <th field="uid" width="40">用户id</th>
	            <th field="name" width="40">姓名</th>
	            <th field="school" width="40">学校</th>
	            <th field="grade" width="40">年级</th>
   	            <th field="due" width="40">到期时间</th>
   	            <th field="phone" width="40">手机</th>
   	            <th field="email" width="40">邮箱</th>
   	            
	        </tr>
	    </thead>
	  </table>
     </div>
    <div id="dlg-buttons4">
	    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="dodispatch()" style="width:90px">Save</a>
	    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg4').dialog('close')" style="width:90px">Cancel</a>
    </div>
    
<div id="dlg5"  class="easyui-dialog" style="width:800px;height:600px;padding:10px 20px" 
        closed="true" buttons="#dlg-buttons5">
          <div class="ftitle" style="text-align:center;">该助理负责的用户</div>
       <table id="dg3" title="" class="easyui-datagrid" 
          pagination="true" rownumbers="true" fitColumns="true"  idField="uid">
	    <thead>
	        <tr>
		        <th field="ck" width="40" checkbox="true"></th>
	            <th field="uid" width="40">用户id</th>
	            <th field="name" width="40">姓名</th>
	            <th field="school" width="40">学校</th>
	            <th field="grade" width="40">年级</th>
   	            <th field="due" width="40">到期时间</th>
   	            <th field="phone" width="40">手机</th>
   	            <th field="email" width="40">邮箱</th>
   	            
	        </tr>
	    </thead>
	  </table>
     </div>
    <div id="dlg-buttons5">
	    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="dodelete()" style="width:90px">delete</a>
	    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg5').dialog('close')" style="width:90px">Cancel</a>
    </div>
<div class="row-fluid">
  <div id="footer" class="span12"> 2016 &copy; <a href="http://themedesigner.in/">guangzhoushuntian information technology</a> </div>
</div>
<!--end-Footer-part-->
</body>
</html>
